package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketAd;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.ManageAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小黑球
 * @datetime 2022/12/28 20:58
 * @description: TODO:
 */
//意味着要响应Json数据
@RestController
@RequestMapping("admin/ad")
public class ManageAdController {

    @Autowired
    ManageAdService manageAdService;

    /**
     * 广告管理的list方法
     * @param info
     * @param name
     * @param content
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info,String name,String content){
        //看响应结果写返回值类型
        CommonData<MarketAd> data=manageAdService.list(info,name,content);
        return BaseRespVo.ok(data);
    }

    /**
     * 广告管理的添加方法
     * @param marketAd
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketAd marketAd){
        MarketAd marketAd1 = manageAdService.create(marketAd);
        return BaseRespVo.ok(marketAd1);
    }

    /**
     * 广告管理的修改方法
     * @param marketAd
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketAd marketAd){
        manageAdService.update(marketAd);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    /**
     * 广告管理的删除方法
     * @param marketAd
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketAd marketAd){
        manageAdService.delete(marketAd);
        return BaseRespVo.ok();
    }

}
